﻿@using Nop.Admin.Models.Logistics
@model PlannedRouteModel
@using Telerik.Web.Mvc.UI

@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;

    //page title
    ViewBag.Title = String.Format("{0}-{1}-{2}", Model.CourierName, Model.PlanId, T("Admin.Logistics.PlannedRoute.Title").Text);
    
    var results = from p in Model.PackageLocations.Where(l => l.Action == "Delivery")
                  group p by p.AddressZone into grps
                  select new
                  {
                      Zone = grps.Key,
                      Count = grps.Select(g => g.PackageId).Distinct().Count()
                  };
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/subsites/Administration/Content/images/ico-catalog.png")" />
        @T("Admin.Logistics.PlannedRoute.Title") <span>: @T("Admin.Logistics.Common.Fields.PlanId") @Model.PlanId.ToString()  ( @Model.CourierName )</span>
    </div>
    <div class="options">
        <a href="@Url.Action("DownloadRouteListAsPdf", new { planId = Model.PlanId })" target="_blank" class="t-button">@T("Admin.Logistics.Common.DownloadPDF")</a>
    </div>
</div>

<ul>
    @foreach (var r in results)
    {
        <li class="adminTitle">@T("Admin.Logistics.Common.Fields.Zone").Text @r.Zone has @r.Count packages to deliver.</li>
    }
</ul>

@(Html.Telerik().Grid<PackageLocationModel>(Model.PackageLocations)
        .Name("planned-route")
        .Columns(columns =>
        {
            columns.Bound(x => x.Rank)
                .Template(x => (int)x.Rank)
                .Width(35)
                .Title(T("Admin.Logistics.PlannedRoute.Fields.RouteOrder").Text);
            columns.Bound(x => x.PackageId)
                .Filterable(true)
                .Centered()
                .Template(x => Html.ActionLink(x.PackageId.ToString(), "PackageEdit", new { id = x.PackageId }))
                .ClientTemplate("<a href=\"PackageEdit/<#= PackageId #>\"><#= PackageId #></a>")
                .HtmlAttributes(new { @class = "packageId" })
                .Width(35)
                .Title(T("Admin.Logistics.Common.Fields.PackageId").Text);
            @*
            columns.Bound(x => x.Type)
                .Template(x => x.Type)
                .Width(0)
                .HtmlAttributes(new { @class = "packageType", style = "display:none;" });
            columns.Bound(x => x.PackageId)
                .Template(x => x.PackageId)
                .Width(0)
                .HtmlAttributes(new { @class = "packageId", style="display:none;" });
            columns.Bound(x => x.Rank)
                .Template(x => x.Rank)
                .Width(0)
                .HtmlAttributes(new { @class = "packageRank", style = "display:none;" });
            *@
            columns.Bound(x => x.ShippingStatus)
                .Title(T("Admin.Logistics.Common.Fields.ShippingStatus").Text);
            columns.Bound(x => x.Action)
                .Title(T("Admin.Logistics.PlannedRoute.Fields.Action").Text);
            columns.Bound(x => x.ReadyTime)
                .Template(x => x.ReadyTimeStr)
                .ClientTemplate("<#= ReadyTimeStr #>")
                .Title(T("Admin.Logistics.Common.Fields.ScheduledPickup").Text);
            columns.Bound(x => x.AddressZone)
                    .Title(T("Admin.Logistics.Common.Fields.Zone").Text);
            columns.Bound(x => x.Address.Type)
                    .Title(T("Admin.Logistics.Common.Fields.AddressType").Text);
            columns.Bound(x => x.Address.FormattedAddress)
                    .Title(T("Admin.Logistics.Common.Fields.Address").Text);
            columns.Bound(x => x.Attribute)
                    .Title(T("Admin.Logistics.Common.Fields.Attribute").Text);
            columns.Bound(x => x.LatestPackageNoteContent)
                    .Title(T("Admin.Logistics.Common.Fields.PackageNote").Text);
            columns.Bound(x => x.Reference)
                    .Title(T("Admin.Logistics.Common.Fields.Reference").Text);
        })
        .Sortable()
        .Reorderable(reorder => reorder.Columns(true))
        .Filterable())


@if (@Model.MapContext != null)
{
    <div>
        <script type="text/javascript">
            $(document).ready(function () {
                getMap();
            })
        </script>
        <table class="stats">
            <tbody>
                <tr>
                    <td class="orderstatistics">
                        @Html.Partial("ShowMap", Model.MapContext)
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
}